<?php
namespace src;
use classlib\acl;
use classlib\input;
use src\logic\Cadmin;
use classlib\core\lang;
use classlib\core as C;
use classlib\core\controller;
class Cindex extends controller {
	/**
	 * 系统ExtJS框架的入口地址
	 * Enter description here ...
	 */
	public function main() {
		$view  = C\view::inst('html');
		$userid= Cadmin::islogin($view);
		Cadmin::share_index($view);
		$access= Cadmin::get_role_access($userid);
		$menu  = Cadmin::get_modules($access['roles'], $access['access']);
		if (empty($menu)) {
			C\redirect('/admin/login.html');
		}
		$view->assign_by_ref('menu', $menu);
		$view->display('index.html');
	}
	
	/**
	 * 活动菜单导航-只支持二级
	 * Enter description here ...
	 */
	public function sidenav() {
		$view   = C\view::inst('json');
		Cadmin::islogin($view);
		$userid = acl::inst()->user['id'];
		$pid 	= (int)input::post('PID');
		$access = Cadmin::get_role_access($userid);
		$pmodule= Cadmin::get_modules($access['roles'], $access['access'], $pid);
		if (empty($pmodule)) {
			$view->assign_error(20002, $lang->txt('index', 20002));
		}
		$pids   = array();
		foreach ($pmodule as &$item) {
			$pids[] = $item['id'];
			if(empty($item['icon'])) {
				$item['icon'] = ' icon-favorite';
			}
			$item['children'] = array();
		}
		//取二级别子导航菜单
		$children = Cadmin::get_modules($access['roles'], $access['access'], $pids);
		foreach ($pmodule as &$pitem) {
			foreach ($children as $citem) {
				if(empty($citem['icon'])) {
					$citem['icon'] = ' icon-favorite';
				}
				if($citem['pid'] == $pitem['id']) {
					$pitem['children'][] = $citem;
				}
			}
		}
		$view->assign_by_ref('dataset', $pmodule);
		$view->display();
	}
}